package com.fulu.javabase.threadpool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest {
    public static void main(String[] args) {
        callableTest();
    }

    private static void callableTest() {
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                return Thread.currentThread().getName();
            }
        };
        FutureTask<String> futureTask = new FutureTask<>(callable);
        new Thread(futureTask, "thread-a1").start();
        try {
            String s = futureTask.get();
            System.out.println(s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    private static void runnableTest() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("runnable");
            }
        }).start();
    }

}

class ThreadTest1 extends Thread{
    @Override
    public void run() {
        System.out.println("thread");
    }
}
